using System;
using System.Collections;

namespace VCDepend.Engine
{
	public class DependencyNode
	{
		public readonly string Name;
		private ArrayList m_dependencies;

		public DependencyNode(string name)
		{
			Name = name;
			m_dependencies = new ArrayList();
		}

		public ICollection Dependencies
		{
			get
			{
				return m_dependencies;
			}
		}

		public void AddDependency(DependencyNode node)
		{
			if (!HasDependency(node))
				m_dependencies.Add(node);
		}

		public void RemoveDependency(DependencyNode dependency)
		{
			m_dependencies.Remove(dependency);
		}

		public bool HasDependency(DependencyNode dependency)
		{
			return m_dependencies.Contains(dependency);
		}

		public DependencyNode FindDependency(string name)
		{
			foreach (DependencyNode node in m_dependencies)
			{
				if (node.Name == name)
					return node;

				return node.FindDependency(name);
			}

			return null;
		}

		public override bool Equals(object obj)
		{
			DependencyNode other = obj as DependencyNode;
			if (other != null)
			{
				return (other.Name == this.Name);
			}

			return false;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

	}
}
